package com.toolset.Activity.ToolItemActivity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.toolset.Activity.BaseActivity;
import com.toolset.R;
import com.toolset.Util.PhoneInfoUtil;

/*
查看设备信息
 */
public class PhoneInfo extends BaseActivity {

    private  AlertDialog alertDialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_info);

        String title = "设备信息", nextLine = "\n\n";

        //工具类
        PhoneInfoUtil phoneInfoUtil = new PhoneInfoUtil();


        //内容
        final String info = phoneInfoUtil.getBrand()
                +nextLine + phoneInfoUtil.getModel()
                +nextLine + phoneInfoUtil.getAndroidversion()
              //  +nextLine + phoneInfoUtil.getRomname()
              //  +nextLine + phoneInfoUtil.getRomversion()
                +nextLine + phoneInfoUtil.getSign()
                +nextLine + phoneInfoUtil.getSdk()
                +nextLine + phoneInfoUtil.getMaker()
                +nextLine + phoneInfoUtil.getSerial()
                +nextLine + phoneInfoUtil.getHost()
                +nextLine + phoneInfoUtil.getProduct()
                +nextLine + phoneInfoUtil.getTags()
                +nextLine + phoneInfoUtil.getVersion_codes_base()
                +nextLine + phoneInfoUtil.getCpu()
                +nextLine + phoneInfoUtil.getCpu2()
                +nextLine + phoneInfoUtil.getBoard()
                +nextLine + phoneInfoUtil.getDevice()
                +nextLine + phoneInfoUtil.getId()
                +nextLine + phoneInfoUtil.getDisplay()
                +nextLine + phoneInfoUtil.getUser()
                +nextLine + phoneInfoUtil.getType()
                +nextLine + phoneInfoUtil.getTime()
                +nextLine + phoneInfoUtil.getUnknown()
                +nextLine + phoneInfoUtil.getRadio()
                +nextLine + phoneInfoUtil.getHardware();

        //弹窗
        alertDialog =  new AlertDialog.Builder(PhoneInfo.this)
                .setTitle(title) //标题
                .setMessage(info) //内容
                //确定关闭弹窗
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        finish();
                    }
                })
                //复制 复制内容 关闭弹窗
                .setPositiveButton("复制", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // 获取系统剪贴板
                        ClipboardManager clipboard = (ClipboardManager) PhoneInfo.this.getSystemService(Context.CLIPBOARD_SERVICE);
                        // 创建一个剪贴数据集，包含一个普通文本数据条目（需要复制的数据）
                        ClipData clipData = ClipData.newPlainText(null, info);
                        // 把数据集设置（复制）到剪贴板
                        clipboard.setPrimaryClip(clipData);

                        Toast.makeText(PhoneInfo.this,"复制成功！", Toast.LENGTH_SHORT).show();

                        finish();
                    }
                }).show();



    }

    //销毁活动 关闭弹窗
    @Override
    protected void onStop() {
        super.onStop();
        if(alertDialog.isShowing()){
            alertDialog.dismiss();
        }
    }
}
